<?php

declare (strict_types = 1);

namespace app\tpwork;

use app\tpwork\helps\Async;
use app\tpwork\helps\Tool;
use own\helps\OwnDecrypt;
use think\worker\Server;

/**
 * 消息推送
 */
class AsynTask extends Server
{
    protected $socket = 'http://0.0.0.0:9523';

    public function onMessage($connection, $request)
    {
        $connection->send(Tool::success());
        $params = $request['post'];
        $sign = $params['sign'] ?? '';
        if($sign && OwnDecrypt::decrypt($sign) == 'tp-async') {
            Async::handle((string) $params['class'], (string) $params['method'], $params['data']);
        }
    }

}
